home *** CD-ROM | disk | FTP | other *** search
- (*===========================================================================*)
- (* Procedure for initialize and shutdown *)
- (* *)
- (* Copyright 1988, 1989, 1990, 1991, 1992 by H. Roy Engehausen. All *)
- (* rights reserved. *)
- (* *)
- (*===========================================================================*)
-
- {$O+} {This procedure gets overlayed}
- {$F+} {Force all far calls}
-
- {$UNDEF DEBUG1} (* Shows progress thru the start code *)
- {$UNDEF DEBUG2} (* Shows progress of heap *)
- {$UNDEF DEBUG3} (* Shows progress thru the end code *)
- {$DEFINE POINT_CHK}
-
- {$DEFINE TEST_VER} (* Display test version message *)
- {$UNDEF TEST_VER} (* Don't display test version message *)
-
- UNIT BBMISCI;
-
- INTERFACE
-
- PROCEDURE main_init;
- PROCEDURE main_close;
- PROCEDURE log_sync;
- PROCEDURE sema_clear_all;
- PROCEDURE shutdown_bbs;
-
- IMPLEMENTATION
-
- USES
- CRT,
- DOS,
- OVERLAY,
- bbaux,
- bbbidaux,
- bbcaptur,
- bbconsl,
- bbdummy,
- bbdump,
- bbfnr,
- bbfsm,
- bbfwdd,
- bbinit,
- bblog,
- bbmf,
- bbmfi,
- bbminit,
- bbmisc3,
- bbmon,
- bbover,
- bbsema2,
- bbstack,
- bbtask,
- bbtime,
- bbuf,
- bbwakeup,
- bbwin,
- match;
-
- (*===========================================================================*)
- (* Routeine to initialize things *)
- (*===========================================================================*)
-
- {$I BBTASKI} (* Task switcher initialization *)
-
- {$I BBLOGI} (* Log init, close, sync *)
-
- {$I BBUFI} (* User init *)
-
- {$I BBSEMAI} (* Semaphore init *)
-
- {$I BBWINIT} (* Window init *)
-
- {$I BBOINIT} (* Option init *)
-
- {$I MATCHI} (* Match init *)
-
- (*===========================================================================*)
- (* Initialize the time *)
- (*===========================================================================*)
-
- {$F+} {Force all far calls}
-
- PROCEDURE time_init;
-
- BEGIN;
-
- up_days := 0;
-
- up_time := 0;
-
- GETTIME(today_time.hour, today_time.min, today_time.sec, sec100);
-
- get_up_time;
-
- new_date;
-
- last_min := today_time.min;
-
- last_hours := today_time.hour;
-
- status_window_change := TRUE;
-
- END;
-
- (*===========================================================================*)
- (* Main initialize *)
- (*===========================================================================*)
-
- PROCEDURE main_init;
-
- PROCEDURE clear_heap;
-
- TYPE
- dt = RECORD
- area : POINTER;
- len : WORD;
- END;
-
- VAR
- i : LONGINT;
- j : BYTE;
- k : WORD;
- p : ARRAY[1..100] OF dt;
-
- BEGIN;
-
- j := 0;
- i := MAXAVAIL;
-
- WHILE i > 0 DO
- BEGIN;
-
- IF i < 65000 THEN
- k := i
- ELSE
- k := 65000;
-
- INC(j);
-
- WITH p[j] DO
- BEGIN;
- GETMEM(area, k);
- len := k;
- FILLCHAR(area^, k, 0);
- END;
-
- i := MAXAVAIL;
-
- END;
-
- WHILE j > 0 DO
- BEGIN;
- WITH p[j] DO
- FREEMEM(area, len);
- DEC(j);
- END;
-
- END;
-
- BEGIN;
-
- (*-----------------------------------------------------------------------*)
- (* Copyright *)
- (*-----------------------------------------------------------------------*)
-
- CLRSCR;
- WRITELN;
- WRITELN(this_bbs_version);
- WRITELN('Copyright 1988, 1989, 1990, 1991 by H.R. Engehausen. ');
- WRITELN('All rights reserved. ');
-
- {$IFDEF TEST_VER}
- WRITELN;
- WRITELN(' ****** WARNING ****** ');
- WRITELN;
- WRITELN('This is a test version. I expect it to have problems so be ');
- WRITELN('prepared. Any problem reports or comments will be welcome. If ');
- WRITELN('this copy is more than two or three weeks old then it is ');
- WRITELN('obsolete and you need a newer copy. When the fully supported ');
- WRITELN('version (2.12) is released, please switch as soon as possible. ');
-
- IF this_bbs_handshake[10] < 'A' THEN
- BEGIN;
- WRITELN;
- WRITELN('******** VIRUS ********');
- WRITELN;
- WRITELN('A virus has infected this program');
- SOUND(440);
- DELAY(2000);
- NOSOUND;
- HALT;
- END;
- {$ENDIF}
-
- (*-----------------------------------------------------------------------*)
- (* Overlay size please *)
- (*-----------------------------------------------------------------------*)
-
- WRITELN;
- WRITELN('Overlay buffer size is ', OVRGETBUF);
-
- (*-----------------------------------------------------------------------*)
- (* Set OVR retry *)
- (*-----------------------------------------------------------------------*)
-
- OVRSETRETRY(OVRGETBUF DIV 10);
-
- (*-----------------------------------------------------------------------*)
- (* Initialize match *)
- (*-----------------------------------------------------------------------*)
-
- match_init;
-
- (*-----------------------------------------------------------------------*)
- (* Let them digest that *)
- (*-----------------------------------------------------------------------*)
-
- DELAY(1000);
-
- (*-----------------------------------------------------------------------*)
- (* A quick init *)
- (*-----------------------------------------------------------------------*)
-
- pointer_bottom_l := main_cs * 16;
- pointer_bottom_p := PTR(main_cs, 0);
-
- {$IFDEF VER55}
- pointer_top_p := FREEPTR;
-
- IF OFS(pointer_top_p^) = 0 THEN
- pointer_top_p := PTR(SEG(pointer_top_p^) + $1000, 0);
- {$ELSE}
- pointer_top_p := HEAPEND;
- {$ENDIF}
-
- pointer_top_l := OFS(pointer_top_p^)
- + LONGINT(16) * SEG(pointer_top_p^);
-
- {$IFNDEF VER55}
- heaporg_l := OFS(HeapOrg^) + LONGINT(16) * SEG(HeapOrg^);
- {$ENDIF}
-
- (*-----------------------------------------------------------------------*)
- (* Zero memory *)
- (*-----------------------------------------------------------------------*)
-
- (* clear_heap; *)
-
- (*-----------------------------------------------------------------------*)
- (* Minor inits *)
- (*-----------------------------------------------------------------------*)
-
- edit_window_busy := FALSE;
-
- msg_route_list := NIL;
- msg_route_num := 0;
- msg_route_force := FALSE;
-
- alias_list := NIL;
-
- wakeup_force := FALSE;
-
- fwd_out_busy := FALSE;
-
- last_h_msg := 0;
-
- first_msg_action := NIL;
-
- wakeup_shut_sw := FALSE;
-
- found_mon := FALSE;
-
- dis_area := NIL;
-
- edit_operation := 0;
-
- fnm_linked_list_valid := FALSE;
-
- RANDOMIZE;
-
- (*-----------------------------------------------------------------------*)
- (* Initialize the dump system *)
- (*-----------------------------------------------------------------------*)
-
- dump_init;
-
- (*-----------------------------------------------------------------------*)
- (* Initialize operator session *)
- (*-----------------------------------------------------------------------*)
-
- operator_init_session;
-
- (*-----------------------------------------------------------------------*)
- (* Initialize the locks *)
- (*-----------------------------------------------------------------------*)
-
- {$IFDEF DEBUG1}
- WRITELN('Semaphore init');
- {$IFDEF DEBUG2}
- dump_string('Semaphore init');
- dump_free_list;
- DELAY(1000);
- {$ENDIF}
- {$ENDIF}
-
- sema_clear_all;
-
- (*-----------------------------------------------------------------------*)
- (* Set the clocks *)
- (*-----------------------------------------------------------------------*)
-
- {$IFDEF DEBUG1}
- WRITELN('Time init');
- {$IFDEF DEBUG2}
- dump_string('Time init');
- dump_free_list;
- DELAY(1000);
- {$ENDIF}
- {$ENDIF}
-
- time_init;
-
- (*-----------------------------------------------------------------------*)
- (* Load options *)
- (*-----------------------------------------------------------------------*)
-
- {$IFDEF DEBUG1}
- WRITELN('Option init');
- (* wakeup_time := 0;
- REPEAT
- INC(wakeup_time);
- UNTIL wakeup_time > $FFFFFF; *)
- {$IFDEF DEBUG2}
- dump_string('Option init');
- dump_free_list;
- DELAY(1000);
- {$ENDIF}
- {$ENDIF}
-
- option_init;
-
- (*-----------------------------------------------------------------------*)
- (* Set the mono signal location *)
- (*-----------------------------------------------------------------------*)
-
- IF opt_block.opt_mono_tcb_trace THEN
- signal_place := PTR($B000, (160 * 11) + 2)
- ELSE
- signal_place := @signal_dummy;
-
- signal_place^ := ORD('X') + $7800;
-
- (*-----------------------------------------------------------------------*)
- (* Trace bringup *)
- (*-----------------------------------------------------------------------*)
-
- {$IFDEF DEBUG1}
- WRITELN('Trace init');
- {$IFDEF DEBUG2}
- dump_string('Trace init');
- dump_free_list;
- {$ENDIF}
- {$ENDIF}
-
- IF opt_block.opt_trace THEN
- BEGIN;
-
- NEW(trace_file);
-
- ASSIGN(trace_file^, opt_block.trace_file_name);
- REWRITE(trace_file^);
-
- trace_count := 0;
- END
- ELSE
- trace_file := NIL;
-
- (*-----------------------------------------------------------------------*)
- (* Schedule WAKEUP in one minute *)
- (*-----------------------------------------------------------------------*)
-
- {$IFDEF DEBUG1}
- WRITELN('Wakeup init');
- {$IFDEF DEBUG2}
- dump_string('Wakeup init');
- dump_free_list;
- {$ENDIF}
- {$ENDIF}
-
- IF opt_block.wakeup_fn = '' THEN
- wakeup_time := $7FFFFFFF
- ELSE
- wakeup_time := current_day_time + ticks_per_min;
-
- (*-----------------------------------------------------------------------*)
- (* Turn capture off *)
- (*-----------------------------------------------------------------------*)
-
- capture_this_window := $FF;
-
- (*-----------------------------------------------------------------------*)
- (* Start log *)
- (*-----------------------------------------------------------------------*)
-
- {$IFDEF DEBUG1}
- WRITELN('Log init');
- {$IFDEF DEBUG2}
- dump_string('Log init');
- dump_free_list;
- {$ENDIF}
- {$ENDIF}
-
- log_init;
-
- (*-----------------------------------------------------------------------*)
- (* Start windows *)
- (*-----------------------------------------------------------------------*)
-
- {$IFDEF DEBUG1}
- WRITELN('Window init');
- DELAY(2000);
- {$IFDEF DEBUG2}
- dump_string('Window init');
- dump_free_list;
- {$ENDIF}
- {$ENDIF}
-
- window_init;
-
- (*-----------------------------------------------------------------------*)
- (* Show we are in system startup for tasks *)
- (*-----------------------------------------------------------------------*)
-
- system_startup := TRUE;
-
- (*-----------------------------------------------------------------------*)
- (* Ready tasks *)
- (*-----------------------------------------------------------------------*)
-
- {$IFDEF DEBUG1}
- WRITELN('Task init');
- DELAY(2000);
- {$IFDEF DEBUG2}
- dump_string('Task init');
- dump_free_list;
- {$ENDIF}
- {$ENDIF}
-
- task_init;
-
- (*-----------------------------------------------------------------------*)
- (* Load the messages *)
- (*-----------------------------------------------------------------------*)
-
- {$IFDEF DEBUG1}
- WRITELN('Message init');
- DELAY(2000);
- {$ENDIF}
-
- message_init(TRUE);
-
- (*-----------------------------------------------------------------------*)
- (* Load the bids *)
- (*-----------------------------------------------------------------------*)
-
- {$IFDEF DEBUG1}
- WRITELN('Bid init');
- DELAY(2000);
- {$IFDEF DEBUG2}
- dump_string('Bid init');
- dump_free_list;
- {$ENDIF}
- {$ENDIF}
-
- bid_init;
-
- (*-----------------------------------------------------------------------*)
- (* Load the msgs *)
- (*-----------------------------------------------------------------------*)
-
- {$IFDEF DEBUG1}
- WRITELN('Msg init');
- DELAY(1000);
- {$IFDEF DEBUG2}
- dump_string('Msg init');
- dump_free_list;
- {$ENDIF}
- {$ENDIF}
-
- open_msg;
-
- (*-----------------------------------------------------------------------*)
- (* Load the user index *)
- (*-----------------------------------------------------------------------*)
-
- {$IFDEF DEBUG1}
- WRITELN('User init');
- DELAY(1000);
- {$IFDEF DEBUG2}
- dump_string('User init');
- dump_free_list;
- {$ENDIF}
- {$ENDIF}
-
- open_uid(opt_block.user_file_name);
-
- (*-----------------------------------------------------------------------*)
- (* Ready monitor *)
- (*-----------------------------------------------------------------------*)
-
- {$IFDEF DEBUG1}
- WRITELN('Monitor init');
- DELAY(1000);
- {$IFDEF DEBUG2}
- dump_string('Monitor init');
- dump_free_list;
- {$ENDIF}
- {$ENDIF}
-
- monitor_init;
-
- (*-----------------------------------------------------------------------*)
- (* Bring up everything else *)
- (*-----------------------------------------------------------------------*)
-
- {$IFDEF DEBUG1}
- WRITELN('Main init');
- DELAY(1000);
- {$IFDEF DEBUG2}
- dump_string('Main init');
- dump_free_list;
- {$ENDIF}
- {$ENDIF}
-
- initialize;
-
- {$IFDEF DEBUG1}
- WRITELN('Init done');
- DELAY(1000);
- {$IFDEF DEBUG2}
- dump_string('Init done');
- dump_free_list;
- {$ENDIF}
- {$ENDIF}
-
- (*-----------------------------------------------------------------------*)
- (* We are done in system startup for tasks *)
- (*-----------------------------------------------------------------------*)
-
- system_startup := FALSE;
-
- END;
-
- (*===========================================================================*)
- (* Close things up *)
- (*===========================================================================*)
-
- PROCEDURE main_close;
-
- VAR
- b : BOOLEAN;
- i : INTEGER;
- t : tcb_ptr;
-
- BEGIN;
-
- (*-----------------------------------------------------------------------*)
- (* Close TNCs *)
- (*-----------------------------------------------------------------------*)
-
- {$IFDEF DEBUG3}
- WRITELN('Tclose');
- DELAY(1000);
- {$ENDIF}
-
- tclose;
-
- (*-----------------------------------------------------------------------*)
- (* Close monitor *)
- (*-----------------------------------------------------------------------*)
-
- {$IFDEF DEBUG3}
- WRITELN('Monitor close');
- DELAY(1000);
- {$ENDIF}
-
- monitor_up;
-
- (*-----------------------------------------------------------------------*)
- (* Close userfile *)
- (*-----------------------------------------------------------------------*)
-
- {$IFDEF DEBUG3}
- WRITELN('UID close');
- DELAY(1000);
- {$ENDIF}
-
- close_uid;
-
- (*-----------------------------------------------------------------------*)
- (* Close msgs *)
- (*-----------------------------------------------------------------------*)
-
- {$IFDEF DEBUG3}
- WRITELN('MSG close');
- DELAY(1000);
- {$ENDIF}
-
- (* close_msg; *)
-
- (*-----------------------------------------------------------------------*)
- (* Close windows *)
- (*-----------------------------------------------------------------------*)
-
- {$IFDEF DEBUG3}
- WRITELN('Window close');
- DELAY(1000);
- {$ENDIF}
-
- window_close;
-
- (*-----------------------------------------------------------------------*)
- (* Close capture file *)
- (*-----------------------------------------------------------------------*)
-
- {$IFDEF DEBUG3}
- WRITELN('Capture close');
- DELAY(1000);
- {$ENDIF}
-
- capture_close;
-
- (*-----------------------------------------------------------------------*)
- (* Close log *)
- (*-----------------------------------------------------------------------*)
-
- {$IFDEF DEBUG3}
- WRITELN('Log close');
- DELAY(1000);
- {$ENDIF}
-
- log_close;
-
- (*-----------------------------------------------------------------------*)
- (* Close trace *)
- (*-----------------------------------------------------------------------*)
-
- {$IFDEF DEBUG3}
- WRITELN('Trace close');
- DELAY(1000);
- {$ENDIF}
-
- IF opt_block.opt_trace THEN
- BEGIN;
-
- t := ring_tcb;
- REPEAT
- stack_record(t);
- t := t^.next_tcb;
- UNTIL t = ring_tcb;
-
- {$I-}
- CLOSE(trace_file^);
- {$I+}
- i := IORESULT;
- END;
-
- (*-----------------------------------------------------------------------*)
- (* Close comple *)
- (*-----------------------------------------------------------------------*)
-
- {$IFDEF DEBUG3}
- WRITELN('Close complete');
- DELAY(1000);
- {$ENDIF}
-
- END;
-
- (*===========================================================================*)
- (* Shutdown the BBS *)
- (*===========================================================================*)
-
- PROCEDURE shutdown_bbs;
-
- VAR
- b : BOOLEAN;
- i : BYTE;
-
- BEGIN;
-
- (*-----------------------------------------------------------------------*)
- (* Obtain the interrupt lock *)
- (*-----------------------------------------------------------------------*)
-
- get_semaphore(semaphore_interrupts, sem_exclusive, FALSE);
-
- (*-----------------------------------------------------------------------*)
- (* Let everything die away *)
- (*-----------------------------------------------------------------------*)
-
- FOR i := 1 TO 20 DO
- task_switch;
-
- (*-----------------------------------------------------------------------*)
- (* Shut system down *)
- (*-----------------------------------------------------------------------*)
-
- shutdown_switch := TRUE;
-
- (*-----------------------------------------------------------------------*)
- (* Release all locks *)
- (*-----------------------------------------------------------------------*)
-
- sema_clear_all;
-
- (*-----------------------------------------------------------------------*)
- (* Done *)
- (*-----------------------------------------------------------------------*)
-
- task_switch;
-
- END;
- END.